home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* File utilities *)
- (* *)
- (* Copyright 1988, 1990, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- UNIT BBFU;
-
- INTERFACE
-
- USES
- DOS,
- bbdummy,
- bbmisc5,
- bbsema2,
- bbstr;
-
- FUNCTION open_text_file(fileid : file_name_str;
- direction_in : BOOLEAN) : STRING;
-
- FUNCTION close_text_file : STRING;
-
- IMPLEMENTATION
-
- (*===========================================================================*)
- (* Open text file *)
- (*===========================================================================*)
-
- FUNCTION open_text_file(fileid : file_name_str;
- direction_in : BOOLEAN) : STRING;
-
- VAR
- io_code : INTEGER;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Generate a fileid if necessary *)
- (*-----------------------------------------------------------------------*)
-
- IF fileid = '' THEN
- fileid := opt_block.msg_file_dir + active_tcb^.port_chan_s + '.IN';
-
- (*-----------------------------------------------------------------------*)
- (* Obtain the interrupt semaphore *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- WITH active_tcb^ DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* Close up any left over files. If there aren't any get a fresh one*)
- (*-------------------------------------------------------------------*)
-
- IF io_fe <> NIL THEN
- BEGIN;
- {$I-}
- CLOSE(io_fe^.fe_text);
- io_code := IORESULT;
- {$I+}
- END
- ELSE
- BEGIN;
- NEW(io_fe);
- FILLCHAR(io_fe^, SIZEOF(io_fe^), CHR(0));
- END;
-
- (*-------------------------------------------------------------------*)
- (* Open the file *)
- (*-------------------------------------------------------------------*)
-
- WITH io_fe^ DO
- BEGIN;
-
- fe_size := 0;
-
- ASSIGN(fe_text, fileid);
-
- {$I-}
- IF direction_in THEN
- RESET(fe_text)
- ELSE
- REWRITE(fe_text);
- io_code := IORESULT;
- {$I+}
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Free the interrupt semaphore. *)
- (*-------------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-------------------------------------------------------------------*)
- (* Generate error message as needed *)
- (*-------------------------------------------------------------------*)
-
- IF io_code = 0 THEN
- open_text_file := ''
- ELSE
- BEGIN;
- open_text_file := dos_err_message(io_code);
- DISPOSE(io_fe);
- io_fe := NIL;
- END;
-
- END;
-
- END;
-
- (*===========================================================================*)
- (* Close text file *)
- (*===========================================================================*)
-
- FUNCTION close_text_file : STRING;
-
- VAR
- io_code : INTEGER;
-
- BEGIN;
-
- WITH active_tcb^ DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* If nothing here, leave *)
- (*-------------------------------------------------------------------*)
-
- IF io_fe = NIL THEN
- BEGIN;
- close_text_file := '';
- EXIT;
- END;
-
- (*-------------------------------------------------------------------*)
- (* Obtain the interrupt semaphore *)
- (*-------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-------------------------------------------------------------------*)
- (* Close up the file (if any) *)
- (*-------------------------------------------------------------------*)
-
- {$I-}
- CLOSE(io_fe^.fe_text);
- io_code := IORESULT;
- {$I+}
-
- (*-------------------------------------------------------------------*)
- (* Free space *)
- (*-------------------------------------------------------------------*)
-
- DISPOSE(io_fe);
- io_fe := NIL;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Free the interrupt semaphore. *)
- (*-----------------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------------*)
- (* Generate error message as needed *)
- (*-----------------------------------------------------------------------*)
-
- IF io_code = 0 THEN
- close_text_file := ''
- ELSE
- close_text_file := dos_err_message(io_code);
-
- END;
-
- END.